# !/usr/bin/env python
# encoding: utf-8
# @File    : track_data_integrated_module.py
# @Time    : 2021/2/15
# @Author  : qiaowei
# @Version : 1.0
# @Email   : weiweiqiao@126.com
# @License : (C) Copyright 2013-2021
# @Brief   :


from PySide2.QtCore import QObject
from PySide2.QtCore import Signal


class TrackData(QObject):
    def __init__(self):
        self.__data_dict = None


    def reset_track_data(self):
        """
        将数据集（dict类型）清空

        """
        if self.__data_dict is not None:
            self.__data_set.clear()


    def setup_track_data(self, content: str):
        """
        根据读取的字符串，将数据项内容按照key/value格式保存到字典self.__data_dict，因为每个字符串的数据项
        个数不一样，字典保存的数据项数量也不一致，每个字符串完成的数据项有17项

        :param content: 要处理的字符串，key/value形式保存的字符串

        """
        if 'sysRecv 1 process' in content.encode('utf-8'):
            self.__init_process_data(content)
        elif 'sysRecv 1 received message' in content:
            pass


    def __init_process_data(self, content: str):
        """"""
        # 获取数据记录的时间hh:mm:ss，保存到字典中
        data_time = content[0: 8]
        self.__data_dict = dict()
        self.__data_dict['data_time'] = data_time

        # 遍历所有key，将key/value保存到字典中，如果value没有值则保存为''
        items_list = content[29:].split(',')
        for item in items_list:
            key, value = item.split("=")
            self.__data_dict[key.strip()] = value.strip()

        print('pause')
        self.sig_track_data_integrated.emit(self.__data_dict)


    # 信号
    sig_track_data_integrated = Signal(dict)
